import Vue from 'vue'
import vuex from 'vuex'
Vue.use(vuex)
export default new vuex.Store({
  state: {
    user: {
      clientId: null, // 用户唯一ID
      deviceId: null // 设备唯一标识,
    },
    refuseReasons: [],
    name: '用户', // 用户名
    status: 'IDLE', // 用户状态
    abnormalType: [], // 异常管理
    warehouses: null, // 仓库
    meun: [], // 主页菜单
    latitude: 0,
    longitude: 0,
    speed: 0,
    interval: 5,
    accuracy: 99999,
    altitudeAccuracy: 99999,
    addresses: '--我在天涯海角--',
    mqtt: '192.168.0.240',
    post: 8083,
    warehouse: '仓库',
    autoLoginStatus: true// 记录是否自动登陆的状态
  },
  mutations: {
    warehouse (state, user) {
      state.warehouse = user.warehouse ? user.warehouse : '仓库'
    },
    logined (state, user) {
      // 变更状态
      state.user.clientId = user.clientId
      state.user.deviceId = user.deviceId
      state.name = user.name
      state.status = user.status
      state.interval = user.interval
      state.mqtt = user.mqtt
      state.post = user.post
      state.warehouse = user.warehouse ? user.warehouse : '仓库'
    },
    getAbnormal (state, abnormal) {
      // 获取异常
      for (let i = 0; i < abnormal.length; i++) {
        state.abnormalType[i] = abnormal[i]
      }
    },
    getMeun (state, usermeun) {
      usermeun.push("ble");
      // state.meun.push({
      //   iconClass: 'iconfont icon-renwuguanli grey',
      //   name: '排队叫号',
      //   museIcon: true,
      //   link: '/lineup'
      // })
      // 获取菜单
      for (let i = 0; i < usermeun.length; i++) {
        switch (usermeun[i]) {
          case 'setting':
            state.meun.push({
              iconClass: 'iconfont icon-shezhi grey',
              name: '设置',
              link: '/set'
            })
            break;
          case 'taskList':
            state.meun.push({
              iconClass: 'iconfont icon-renwuguanli orange',
              name: '任务查询',
              link: '/task'
            })
            break;
          case 'recieveCar':
            state.meun.push({
              iconClass: 'iconfont icon-shoucheguanli yellow',
              name: '下线收车',
              link: '/pickcar'
            })
            break;
          case 'exceptionManager':
            state.meun.push({
              iconClass: 'iconfont icon-yichang olive',
              name: '异常管理',
              link: '/abnormal'
            })
            break;
          case "opsitionLocation":
            state.meun.push({
              iconClass: 'iconfont icon-location2 green',
              name: '库位定位',
              link: '/location'
            })
            break;
          case "enterScan":
            state.meun.push({
              iconClass: 'iconfont icon-ruku cyan',
              name: '入场扫描',
              link: '/inplace'
            })
            break;
          case "storageManager":
            state.meun.push({
              iconClass: 'iconfont icon-zhengcheruku blue',
              name: '入库管理',
              link: '/inlibrary'
            })
            break;
          case "exitScan":
            state.meun.push({
              iconClass: 'iconfont icon-zhengchechuku purple',
              name: '出库管理',
              link: '/outlibrary'
            })
            break;
          case "busTask":
            state.meun.push({
              iconClass: 'iconfont icon-jiaotongche1 mauve',
              name: '交通车管理',
              link: '/trafficcar'
            })
            break;
          case "moveOnWay":
            state.meun.push({
              iconClass: 'iconfont icon-yiku pink',
              name: '移库出场',
              link: '/movelibrary'
            })
            break;
          case "rideCarManager":
            state.meun.push({
              iconClass: 'iconfont icon-jiaochefuwu brown',
              name: '乘车管理',
              link: '/callcar'
            })
            break;
          case "outStorageManager":
            state.meun.push({
              iconClass: 'iconfont icon-chuku red',
              name: '出场扫描',
              link: '/outplace'
            })
            break;
            case "moveManager":
              state.meun.push({
                iconClass: 'iconfont icon-yiquyiwei black',
                name: '移位管理',
                link: '/transposing'
              })
              break;
            case "mainManager":
              state.meun.push({
                iconClass: 'iconfont icon-weihu darkGray',
                name: '维护管理',
                link: '/maintain'
              })
              break;
            case "countManager":
              state.meun.push({
                iconClass: 'iconfont icon-ccgl-pandianjilu-1 gray',
                name: '盘点管理',
                link: '/inventory'
              })
              break;
            case "fill":
              state.meun.push({
                iconClass: 'iconfont icon-buchong ghostWhite',
                name: '补人管理',
                link: '/fill'
              })
              break;
            case "roadfetch":
              state.meun.push({
                iconClass: 'iconfont icon-fukuanquche brown',
                name: '路试取车',
                link: '/roadfetch'
              })
              break;
            case "transitfetch":
              state.meun.push({
                iconClass: 'iconfont icon-wangyueche_huaban1 brown',
                name: '在途取车',
                link: '/transitfetch'
              })
              break;
            case "markver":
              state.meun.push({
                iconClass: 'iconfont icon-yanzheng brown',
                name: '唛头验证',
                link: '/markver'
              })
              break;
            case "liftcarver":
              state.meun.push({
                iconClass: 'iconfont icon-ticheyanche brown',
                name: '提车验证',
                link: '/liftcarver'
              })
              break;
            case "ble":
              state.meun.push({
                iconClass: 'iconfont icon-lanya blue',
                name: '蓝牙配置',
                museIcon: true,
                link: '/ble?fromWhere=1'
              })
              break;
            case "lineup":
              state.meun.push({
                iconClass: 'iconfont icon-renwuguanli grey',
                name: '排队叫号',
                museIcon: true,
                link: '/lineup'
              })
              break;
          case 'returnTaskList':
            state.meun.push({
              iconClass: 'iconfont icon-renwuguanli orange',
              name: '返修任务查询',
              museIcon: true,
              link: '/returnTask'
            })
            break;
          default:
            break;
        }
      }
    },
    initMeun (state) {
      state.meun = []
    },
    setWarehouses (state, warehouses) {
      // 设置仓库
      console.log(warehouses);
      state.warehouses = warehouses
    },
    setStatus (state, status) {
      // 更改状态
      state.status = status
    },
    setReasons (state, reasons) {
      state.refuseReasons = reasons
    },
    setGeolocation (state, geo) {
      state.latitude = geo.latitude
      state.longitude = geo.longitude
      state.speed = geo.speed
      state.addresses = geo.addresses
      state.accuracy = geo.accuracy
      state.altitudeAccuracy = geo.altitudeAccuracy
    },
    setAutoLoginStatus (state) {
      state.autoLoginStatus = false
    }
  }
})
